package com.study.homework;

import java.util.ArrayList;
import java.util.List;

public class StringUtils {

	/**
	 * eg: countSubString("aabb","ab") "a"出现2次,b出现2次,总共4次
	 * 	   countSubString("aabb","aba")"a"出现2次,b出现2次,a重复,第二次不记入总数,总共4次
	 * @param originalStr
	 * @param subStr
	 * @return
	 */
	public static int countSubString(String originalStr,String subStr){
		if (originalStr==null || subStr==null ||originalStr.isEmpty()||subStr.isEmpty()) {
			return 0;
		}
		char[] originalChars = originalStr.toCharArray();
		char[] subChars = subStr.toCharArray();
		int countNum=0;
		List<String> list =new ArrayList<String>();
		for (int i = 0; i < subChars.length; i++) {
			String newStr = new String(subChars,i,1);
			if (list.contains(newStr)) {
				continue;
			}
			list.add(newStr);
			for (int j = 0; j < originalChars.length; j++) {
				if (originalChars[j] == subChars[i]) {
					countNum++;
				}
			}
		}
		return countNum;
	}
	public static void main(String[] args) {
//		System.out.println(countSubString("aabb","abac"));
	
	
	}
}
